package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划相关接口")
public class NursingPlanController extends BaseController{

    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping
    @ApiOperation("查询全部护理计划")
    public ResponseResult getAllPlan(){
        List<NursingPlanVo> allPlan = nursingPlanService.getAllPlan();
        return success(allPlan);
    }

    @PostMapping
    @ApiOperation("新增护理计划")
    public ResponseResult addPlan(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.addPlan(nursingPlanDto);
        return success();
    }

    @GetMapping("/search")
    @ApiOperation("条件分页查询护理计划")
    public ResponseResult getByPage(String name, Integer pageNum, Integer pageSize, Integer status){
        PageResponse pageResponse = nursingPlanService.getByPage(name, pageNum, pageSize, status);
        return success(pageResponse);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理计划")
    public ResponseResult getById(@PathVariable Integer id){
        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);
        return success(nursingPlanVo);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改护理计划")
    public ResponseResult update(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.update(nursingPlanDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除护理计划")
    public ResponseResult delete(@PathVariable Integer id){
        nursingPlanService.delete(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("控制护理计划")
    public ResponseResult openAndClose(@PathVariable Integer id, @PathVariable Integer status){
        nursingPlanService.openAndClose(id,status);
        return success();
    }

}
